Rust library for OEM Code pages
This library handles many SBCS (single byte character sets) that are used as OEM code pages. OEM code pages are used for encoding file names in ZIP archives and characters in the terminal in Windows today.
Supported code pages
Code Page | Note |
---|---|
437 | OEM United States |
720 | Arabic (Transparent ASMO); Arabic (DOS) |
737 | OEM Greek (formerly 437G); Greek (DOS) |
775 | OEM Baltic; Baltic (DOS) |
850 | OEM Multilingual Latin 1; Western European (DOS) |
852 | OEM Latin 2; Central European (DOS) |
855 | OEM Cyrillic (primarily Russian) |
857 | OEM Turkish; Turkish (DOS) |
858 | OEM Multilingual Latin 1 + Euro symbol |
860 | OEM Portuguese; Portuguese (DOS) |
861 | OEM Icelandic; Icelandic (DOS) |
862 | OEM Hebrew; Hebrew (DOS) |
863 | OEM French Canadian; French Canadian (DOS) |
864 | OEM Arabic; Arabic (864) |
865 | OEM Nordic; Nordic (DOS) |
866 | OEM Russian; Cyrillic (DOS) |
869 | OEM Modern Greek; Greek, Modern (DOS) |
874 | ANSI/OEM Thai (ISO 8859-11); Thai (Windows) |
Notes are quoted from https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
How to use
Add oem_cp
to the dependencies in Cargo.toml
in your projects.
[]
# *snip*
= "2"
# *snip*
Examples
Use specific code pages
Encoding Unicode string to SBCS bytes
use ;
use ;
assert_eq!;
// Archimedes in Greek
assert_eq!;
// ¾ (U+00BE) is not included in CP437
assert_eq!;
// Unknown characters can be replaced with ? (0x3F)
assert_eq!;
Decoding SBCS bytes to Unicode string
use ;
use ;
assert_eq!;
// For encoding that has some undefined code points, you must use decode_string_incomplete_table_{checked,lossy} instead of decode_string_complete_table
// means shrimp in Thai (U+E49 => 0xE9)
assert_eq!;
// 0xDB-0xDE,0xFC-0xFF is undefined in CP874 in Windows
assert_eq!;
// You can use decode_string_incomplete_table_lossy instead
assert_eq!;
// Undefined code points are replaced with U+FFFD (replacement character)
assert_eq!;
Select appropriate codepage from integer
use ;
use ;
if let Some = .get else
if let Some = .get else
Support for ANSI/EBCDIC/MBCS code pages
For ANSI (125x) and MBCS (932-950; for CJK languages) code pages, please use encoding_rs instead.
This library is only for extended ASCII encodings (0x00-0x80 must be compatible with ASCII), so EBCDIC encodings will never be supported.
Symbols from 0x01 to 0x19
This library doesn't support symbols mapped from 0x01 to 0x19 in CP437. 0x01-0x19 are mapped to U+0001-U+0019. If you prefer symbols, use codepage_437 instead.
Licenses
MIT